import logging
import time
import pandas as pd
from functools import wraps
def retry(max_retries=3, delay=2):
    def decorator(func):
        @wraps(func)
        def wrapper(*args, **kwargs):
            retries = 0
            while retries < max_retries:
                try:
                    return func(*args, **kwargs)
                except Exception as e:
                    retries += 1
                    logging.warning(f"尝试 {retries}/{max_retries} 失败: {e}")
                    time.sleep(delay)
            logging.error(f"所有重试失败")
            return pd.DataFrame()
        return wrapper
    return decorator